package cn.micai.core.service.user;

import cn.micai.common.page.Pagination;
import cn.micai.core.bean.user.Admin;
import cn.micai.core.dao.user.AdminDao;
import cn.micai.core.query.user.AdminQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 管理员
 * @author lixu
 * @Date [2014-3-27 下午03:31:57]
 */
@Service
@Transactional
public class AdminServiceImpl implements AdminService {

	@Resource
	AdminDao adminDao;

	/**
	 * 插入数据库
	 * 
	 * @return
	 */
	public Integer addAdmin(Admin admin) {
		return adminDao.addAdmin(admin);
	}

	/**
	 * 根据主键查找
	 */
	@Transactional(readOnly = true)
	public Admin getAdminByKey(String id) {
		return adminDao.getAdminByKey(id);
	}

	/**
	 * 根据username查找
	 */
	@Transactional(readOnly = true)
	public Admin getAdminByUsername(String username) {
		return adminDao.getAdminByUsername(username);
	}
	
	@Transactional(readOnly = true)
	public List<Admin> getAdminsByKeys(List<String> idList) {
		return adminDao.getAdminsByKeys(idList);
	}

	/**
	 * 根据主键删除
	 * 
	 * @return
	 */
	public Integer deleteByKey(String id) {
		return adminDao.deleteByKey(id);
	}

	public Integer deleteByKeys(List<String> idList) {
		return adminDao.deleteByKeys(idList);
	}

	/**
	 * 根据主键更新
	 * 
	 * @return
	 */
	public Integer updateAdminByKey(Admin admin) {
		return adminDao.updateAdminByKey(admin);
	}
	
	@Transactional(readOnly = true)
	public Pagination getAdminListWithPage(AdminQuery adminQuery) {
		Pagination p = new Pagination(adminQuery.getPageNo(),adminQuery.getPageSize(),adminDao.getAdminListCount(adminQuery));
		p.setList(adminDao.getAdminListWithPage(adminQuery));
		return p;
	}
	
	@Transactional(readOnly = true)
	public List<Admin> getAdminList(AdminQuery adminQuery) {
		return adminDao.getAdminList(adminQuery);
	}
}
